/*******************************************************************************

PooledRegions analysis_villagelevelaccess.do

2022.04.17 (DJ) Created

This do file runs the price heterogeneity regression using lower and upper bound 
estimates of travel cost per km. 

See PooledRegions travelcost_robust_Master.do
*******************************************************************************/

		
/*******************************************************************************
	append Manyara and Kilimanjaro Data sets
*******************************************************************************/
// Kilimanjaro
	use `kilimanjaroViltoAV', clear
	merge 1:1 village_name ward district using "${analysis}/Kilimanjaro google_ViltoCities.dta"
	drop _merge
	rename (district ward village_name) (survey_district survey_ward survey_village)
	
	gen survey_region="Kilimanjaro"
	
	tempfile kili_vilaccess
	save `kili_vilaccess'
	
// Manyara
	use `manyaraViltoAV', clear
	merge 1:1 village_id using "${analysis}/Manyara ViltoCities_dist.dta"
	drop _merge
	
append using `kili_vilaccess'

fsum `market_access_varlist'

// generate MARKET ACCESS PROXIES
	foreach var in city_km city_hrs nearcity_km{
		gen l_google_vil_`var' = log(google_vil_`var')
		egen std_google_vil_`var' = std(google_vil_`var')
	}	
	

	gen DH_access = .
	foreach city in moshi arusha babati dodoma tanga{
		replace DH_access = 0 if !mi(google_vil_`city'_km)
	}
	foreach city in moshi arusha babati dodoma tanga{
		gen tau_`city' = 2.7*(0.9392 + 0.02019*google_vil_`city'_km)/25
		replace DH_access = DH_access + (1 + tau_`city')^(${elasticity})*pop_frac_`city'
	}
	egen DH_access_std = std(DH_access)
	replace DH_access_std = -DH_access_std

	
	
foreach indep in std_google_vil_city_km DH_access_std{
	foreach out in  min_DR_adj_price_50kg unadjusted_price_50kg_DR travelcost_DR_adj_av_urea_usd{
		eststo: reg `out' `indep', robust
		sum `out' if e(sample) 
			estadd scalar ybar = r(mean)
			estadd scalar ysd = r(sd)
	}
}

	
